import dayjs, { Dayjs } from 'dayjs';
import { useCommon } from "@/stores/Common"
import { useTestTube } from "@/stores/TestTube"
import { storeToRefs } from 'pinia';
import { computed, reactive, ref } from 'vue';
const CommonStore = useCommon()
const TestTubeStore = useTestTube()

const { SelfDeviceOptions, SecondLeafArr } = storeToRefs(CommonStore)

const putDisabled = ref(true)
const outDisabled = ref(false)

export const searchConfig = reactive({
    TableKey: {
        component: 'ARadioGroup',
        label: '类型',
        attrs: {
            allowClear: true,
            optionType: 'button',
            buttonStyle: "solid",
            options: [
                { label: '取样', value: 'out' },
                { label: '放样', value: 'put' }
            ],
            onChange(e: any) {
                TestTubeStore.searchForm.pageNo = 1
                TestTubeStore.searchForm.current = 1
                e.target.value == 'out' ? TestTubeStore.getOutTableData() : TestTubeStore.getPutTableData()
                putDisabled.value = !putDisabled.value
                outDisabled.value = !outDisabled.value
            },
            style: {
                width: '100%'
            }
        },
    },
    serial: {
        component: 'ASelect',
        label: '设备名称',
        attrs: {
            allowClear: true,
            placeholder: '设备名称',
            showSearch: true,
            options: SelfDeviceOptions,
            filterOption: (input: string, option: any) => {
                return option.label.includes(input)
            },
            style: {
                width: '100%'
            }
        },
    },
    departmentWard: {
        component: "ACascader",
        label: "科室",
        attrs: {
            allowClear: true,
            placeholder: "科室",
            changeOnSelect: true,
            options: SecondLeafArr,
            style: {
                width: '100%'
            }
        },
    },
    outInfo: {
        component: "AInput",
        label: "工号",
        attrs: computed(() => ({
            allowClear: true,
            disabled: outDisabled.value,
            placeholder: "工号",
            style: {
                width: '100%',
            },
        }))
    },
    putInfo: {
        component: "AInput",
        label: "放样码",
        attrs: computed(() => ({
            allowClear: true,
            disabled: putDisabled.value,
            placeholder: "放样码",
            style: {
                width: '100%',
            },
        }
        ))
    },
    jianchamingcheng: {
        component: "AInput",
        label: "项目名称",
        attrs: computed(() => ({
            allowClear: true,
            placeholder: "项目名称",
            disabled: putDisabled.value,
            style: {
                width: '100%',
            },
        }))
    },
    TimeArr: {
        component: 'ARangePicker',
        label: '时间',
        attrs: {
            allowClear: true,
            placeholder: ['开始时间', '结束时间'],
            valueFormat: 'YYYY-MM-DD',
            format: 'YYYY-MM-DD',
            style: {
                width: '100%'
            }
        },
    }
})

export const searchSelfConfig = reactive({
    TableKey: {
        component: 'ARadioGroup',
        label: '类型',
        attrs: {
            allowClear: true,
            placeholder: '序列号',
            optionType: 'button',
            buttonStyle: "solid",
            options: [
                { label: '取样', value: 'out' },
                { label: '放样', value: 'put' }
            ],
            onChange(e: any) {
                TestTubeStore.searchForm.pageNo = 1
                TestTubeStore.searchForm.current = 1
                e.target.value == 'out' ? TestTubeStore.getOutTableData() : TestTubeStore.getPutTableData()
            }, style: {
                width: '100%'
            }
        },
    },
    serial: {
        component: 'ASelect',
        label: '设备名称',
        attrs: {
            allowClear: true,
            placeholder: '设备名称',
            showSearch: true,
            options: SelfDeviceOptions,
            filterOption: (input: string, option: any) => {
                return option.label.includes(input)
            },
            style: {
                width: '100%'
            }
        },
    },
    outInfo: {
        component: "AInput",
        label: "工号",
        attrs: {
            allowClear: true,
            placeholder: "工号", style: {
                width: '100%'
            }
        },
    },
    putInfo: {
        component: "AInput",
        label: "放样码",
        attrs: {
            allowClear: true,
            placeholder: "放样码", style: {
                width: '100%'
            }
        },
    },
    jianchamingcheng: {
        component: "AInput",
        label: "项目名称",
        attrs: {
            allowClear: true,
            placeholder: "项目名称",
            style: {
                width: '100%'
            }
        },
    },
    TimeArr: {
        component: 'ARangePicker',
        label: '时间',
        attrs: {
            allowClear: true,
            placeholder: ['开始时间', '结束时间'],
            valueFormat: 'YYYY-MM-DD',
            format: 'YYYY-MM-DD', style: {
                width: '100%'
            }
        },
    }
})

export const exportConfig = {
    TimeArr: {
        component: 'ARangePicker',
        label: '时间',
        attrs: {
            allowClear: true,
            placeholder: ['开始时间', '结束时间'],
            valueFormat: 'YYYY-MM-DD',
            format: 'YYYY-MM-DD',
            defaultPickerValue: [dayjs().subtract(3, 'month'), dayjs().add(0, 'day')],
            disabledDate: (current: Dayjs) => {
                const lastDate = dayjs().subtract(3, 'month')
                const tomorrow = dayjs().add(0, 'day')
                return (lastDate > current || tomorrow < current)
            },
            onCalendarChange(e: string[]) {
                TestTubeStore.exportForm.startData = e[0]
                TestTubeStore.exportForm.endData = e[1]
            },
            style: {
                width: '100%'
            }
        },
        rules: [{ required: true, message: '请选择时间', trigger: 'change' }]
    }
}


export const outColumns = [
    {
        title: '序号',
        dataIndex: 'index',
        align: 'center',
        width: 80,
        fixed: 'left'
    }, {
        title: '科室',
        dataIndex: 'departmentWard',
        width: 300,
        align: 'center',
        customRender: ({ record }: { record: any }) => record.illArea ? `${record.department}-${record.illArea}` : record.department
    }, {
        title: '取样设备名称',
        dataIndex: 'deviceName',
        align: 'center',
    },
    // {
    //     title: '序列号',
    //     dataIndex: 'serial',
    //     align: 'center',
    // },
    {
        title: '取样人',
        dataIndex: 'name',
        align: 'center',
    }, {
        title: '性别',
        dataIndex: 'sex',
        align: 'center',
    }, {
        title: '工号',
        dataIndex: 'outInfo',
        align: 'center',
    }, {
        title: '取样时间',
        dataIndex: 'outData',
        align: 'center',
    }, {
        title: '取样详情',
        dataIndex: 'outUrl',
        align: 'center',
    }
]

export const putColumns = [
    {
        title: '序号',
        dataIndex: 'index',
        align: 'center',
        width: 80,
        fixed: 'left'
    }, {
        title: '科室',
        dataIndex: 'departmentWard',
        align: 'center',
        customRender: ({ record }: { record: any }) => record.illArea ? `${record.department}-${record.illArea}` : record.department
    }, {
        title: '放样设备名称',
        dataIndex: 'deviceName',
        align: 'center',
    },
    {
        title: '患者姓名',
        dataIndex: 'name',
        align: 'center',
    },
    // {
    //     title: '序列号',
    //     dataIndex: 'serial',
    //     align: 'center',
    // },
    {
        title: '项目名称',
        dataIndex: 'jianchamingcheng',
        align: 'center'
    }, {
        title: '放样条形码',
        dataIndex: 'putInfo',
        align: 'center',
    }, {
        title: '放样时间',
        dataIndex: 'putData',
        align: 'center',
    }, {
        title: '放样详情',
        dataIndex: 'putUrl',
        align: 'center',
    }
]

export const infoColumns = [
    {
        title: '序号',
        dataIndex: 'index',
        align: 'center',
        width: 80,
        fixed: 'left'
    }, {
        title: '患者姓名',
        dataIndex: 'name',
        align: 'center',
    }, {
        title: '放样时间',
        dataIndex: 'putData',
        align: 'center',
    }, {
        title: '放样设备',
        dataIndex: 'deviceName',
        align: 'center',
    }, {
        title: '项目名称',
        dataIndex: 'jianchamingcheng',
        align: 'center',
    }, {
        title: '放样条形码',
        dataIndex: 'putInfo',
        align: 'center',
    }, {
        title: '放样详情',
        dataIndex: 'putUrl',
        align: 'center',
    }
]